package demo.demo04;

public class ArrayInit {
    public static void main(String[] args) {
        int[] array = {1, 2, 3, 4, 5, 6};//静态初始化
        int sum = 0;
        for (int i = 0; i <= array.length - 1; i++) {
            sum += array[i];
        }
        System.out.println(sum);

        int array1[] = new int[6];//动态初始化1
        array1[0] = 10;
        array1[1] = 10;
        array1[2] = 10;
        array1[3] = 10;
        array1[4] = 10;
        array1[5] = 10;
        int sum1 = 0;
        for (int j = 0; j <= array1.length - 1; j++) {
            sum1 += array1[j];
        }
        System.out.println(sum1);

        int array2[];//动态初始化2
        array2 = new int[6];
        array2[0] = 10;
        array2[1] = 20;
        array2[2] = 30;
        array2[3] = 40;
        array2[4] = 50;
        array2[5] = 10;
        int sum2 = 0;
        for (int k = 0; k <= array2.length - 1; k++) {
            sum2 += array2[k];
        }
        System.out.println(sum2);
    }
}